const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            photo,
            showDialog1: false,
            page: {
                activeName:'first',
                value1: '',
                value2: '',
                value3: '',
                value4: '',
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%,%%,%%,%%"))),
                ExtensionCondition: ''
            },
            str:'',
            str1:'',
            agricultural_machinery_category:[],
        };
    },
    mounted() {

    },
    methods: {
        changeValue4(val) {
            if (val == null) {
                this.page.value4 = ''
            }
        },
        handleClick(){
            if (this.page.activeName == 'first') {
                this.str1 = '';
            } else if (this.page.activeName == 'second') {
                this.str1 = "\r\nAND agricultural_machinery.Row_Status = '2'";
            } else if (this.page.activeName == 'third') {
                this.str1 = "\r\nAND agricultural_machinery.Row_Status = '0'";
            } else if (this.page.activeName == 'fourth') {
                this.str1 = "\r\nAND agricultural_machinery.Row_Status = '3'";
            }
            this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str + this.str1)));
            this.postgetList(this.page)
        },
        // submitSave() {
        //     this.websocket = new WebSocketClient();
        //     this.websocket.init({
        //         url: `${ws}/generalSave/${getCookie('token')}`,
        //         onopen: () => {
        //             console.log('websocket已开启');
        //         },
        //         onmessage: (data) => {
        //             try {
        //                 const res = JSON.parse(data);
        //                 if (res.REDIRECT && res.REDIRECT == 'REDIRECT') {//重定向
        //                     removeCookie("token");
        //                     removeCookie("user");
        //                     sessionStorage.setItem("REDIRECT", "登录已过期，请重新登录！");
        //                     window.parent.document.location.href = absolutepath() + res.CONTENTPATH;
        //                 } else {
        //                     if (res.Action == 'Delete') {//删除
        //                         if (res.Status == 'success') {
        //                             this.postgetList(this.page);
        //                         } else {
        //                             this.$message({
        //                                 type: 'error',
        //                                 message: '删除失败'
        //                             });
        //                         }
        //                     } else if (res.Action == "Examine") {
        //                         if (res.Status == 'success') {
        //                             this.postgetList(this.page);
        //                         } else {
        //                             this.$message({
        //                                 type: 'error',
        //                                 message: '操作失败'
        //                             });
        //                         }
        //                     }
        //                 }
        //             } catch (error) { }
        //         },
        //     })
        //     window.addEventListener("beforeunload", () => {
        //         this.websocket.close();
        //     });
        // },
        //树的数据
        Treedata() {
            const _this = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/clientOperation/getDistrictTree`,
                type: "GET",
                data: {
                    DistrictCode: '232723'
                },
                success: (data) => {
                    this.treeData = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'agricultural_machinery_category',
                    Condition: `Row_Status='0'`,
                },
                success: (res) => {
                    this.agricultural_machinery_category = res;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                },
            });
        },
        //查询按钮
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%"+this.page.value3+"%,%"+this.page.value2+"%,%"+this.page.value4+"%")));
            this.postgetList(this.page)
        },
        handle1(data,is){
            this.$confirm('该操作将'+ (is=='0'?'审核通过':is=='2'?'重新审核':is=='3'?'审核拒绝':'')+'此条数据,是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    method: "post",
                    data: {
                        Data: TableName,
                        Condition: primary_key + "='" + data[primary_key] + "'"
                    },
                    success: (res) => {
                        if (res.length == 1) {
                            res[0].Row_Status = is;
                            let lJSONObject_DataSet = new Object();
                            let lJSONObject_Table = new Object();
                            lJSONObject_Table[TableName] = res;
                            lJSONObject_DataSet['Modify'] = lJSONObject_Table;
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            if (!lJSONObject_DataSet['Add']) {
                                lJSONObject_DataSet['Add'] = new Object();
                            }
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSave",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet,(res)=>{
                                if (res.Status == 'success') {
                                    this.postgetList(this.page);
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '操作失败'
                                    });
                                }
                            });
                            // this.websocket.send(JSON.stringify({ Data: lJSONObject_DataSet, Action: 'Examine', AccessToken: getCookie('token') }));
                        } else {
                            this.$message({
                                type: 'error',
                                message: '操作失败'
                            });
                        }

                    },
                    complete: (XMLHttpRequest) => {
                 
                        requestPretreatment(XMLHttpRequest);
                    }
                });
            }).catch(() => { });
        },
        handleNodeClick(data, node) {
            this.page.value3 = data.ProvinceNumber
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%," + this.page.value3 + "%,%"+this.page.value2+"%,%"+this.page.value4+"%")));
            this.postgetList(this.page)
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.use(ElementPlus);
app.mount("#app");
